import DictDataService from "~/service/module/system/dictdata"
import { addForm } from "./_form_table"
import { Code } from "~/utils/enums"


const useUpdate = () => {
    const dictDataService = new DictDataService()
    const submit = async () => {
        const payload = addForm.getBindingValue()
        if (!addForm.dictCode) {
            const res = await dictDataService.insertDictData(payload)
            if (res.code === Code.SUCCESS) {
                $message.success('新增成功')
            }
        } else {
            const res = await dictDataService.updateDictData({ dictCode: addForm.dictCode, ...payload })
            if (res.code === Code.SUCCESS) {
                $message.success('修改成功')
            }
        }
    }


    return {
        submit
    }
}

export default useUpdate